/*
 * server.h
 *
 *  Created on: Nov 13, 2013
 *      Author: killerg
 */

#ifndef SERVER_H_
#define SERVER_H_

struct server_cfg_t;
struct con_cmd_handler_t;
struct my_clock_t;
struct db_mgr_t;
struct logon_session_t;
struct net_s;
struct gm_cmd_handler_t;
struct tran_s;
struct client_session_t;

struct ProtoMgr;
struct player_mgr;
struct occupation_mgr;
struct arena_t;
struct rank_mgr;
struct chatmgr_t;
struct auth_mgr;
struct game_cfg_t;
struct mailmgr_t;
struct svr_console_t;
struct bill_session_t;
struct world_boss_t;
struct WordFilter;
struct pointrank_t;
struct giveback_mgr_t;

template<typename T, typename S>
struct connection_mgr;


template<int STAGE_NUM>
struct profiler_t;

#include "client_session.h"
#include "share/co.pb.h"

struct SvcData;

struct proc_t {
    bool init(SvcData* svcdata);
    void destroy();
    void loop();

    svr_console_t* console;
    server_cfg_t* cfg;
    my_clock_t* clock;
    ProtoMgr* protomgr;
    db_mgr_t* db_fast;
    db_mgr_t* db_slow;
    db_mgr_t* db_log;

    player_mgr* playermgr;
    occupation_mgr* occupation;
    logon_session_t* logonsess;
    gm_cmd_handler_t* gm_cmd_handler;
    auth_mgr* authmgr;
    arena_t* arena;
    rank_mgr* rank;
    game_cfg_t* game_cfg;
    mailmgr_t* mail;
    world_boss_t* worldboss;
    chatmgr_t* chat;
    clientsess_mgr_t* sessmgr;
    bill_session_t* bill;
    WordFilter* wordfilter;
    pointrank_t* pr;
    SvcData* svcdata;
    giveback_mgr_t* giveback;

    co::EServerStatus status;

    int count[ESSTAGENUM];
    int32_t last_recv;
    int32_t last_send;
    double last_total_time;
    double recv_speed;
    double send_speed;

    time_t server_begin = -1;

#define TIMER_DEC(name) \
    double name##_time = 0; \
    double name##_pct = 0

    TIMER_DEC(total);
    TIMER_DEC(sessmgr);
    TIMER_DEC(authmgr);
    TIMER_DEC(logonsess);
    TIMER_DEC(occupation);
    TIMER_DEC(arena);
    TIMER_DEC(playermgr);
    TIMER_DEC(db_fast);
    TIMER_DEC(db_slow);
    TIMER_DEC(db_log);
    TIMER_DEC(mail);
    TIMER_DEC(worldboss);
    TIMER_DEC(chat);
    TIMER_DEC(console);
    TIMER_DEC(bill);
    TIMER_DEC(rank);
    TIMER_DEC(pr);

};

extern proc_t g_svr;

#define g_cfg             g_svr.cfg
#define g_clock           g_svr.clock
#define g_protomgr        g_svr.protomgr
#define g_dbf             g_svr.db_fast
#define g_dbs             g_svr.db_slow
#define g_dbl             g_svr.db_log
#define g_playermgr       g_svr.playermgr
#define g_occupation      g_svr.occupation
#define g_logonsess       g_svr.logonsess
#define g_gm_cmd_handler  g_svr.gm_cmd_handler
#define g_sessmgr         g_svr.sessmgr
#define g_authmgr         g_svr.authmgr
#define g_acceptor        g_svr.svr.acceptor
#define g_arena           g_svr.arena
#define g_rank            g_svr.rank
#define g_pr      		  g_svr.pr
#define g_game_cfg        g_svr.game_cfg
#define g_mail            g_svr.mail
#define g_worldboss       g_svr.worldboss
#define g_chat            g_svr.chat
#define g_console         g_svr.console
#define g_bill            g_svr.bill
#define g_wordfilter      g_svr.wordfilter

#endif /* SERVER_H_ */
